from flask import Flask
# HTML模板渲染
from flask import render_template
# 引入request
from flask import request

app = Flask(__name__, template_folder='../templates')


# 基于表单form提交方式

@app.route('/login', methods=['POST', 'GET'])
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] == 'test':
            return 'test 用户'
        else:
            error = 'Invalid username/password'
    return render_template('login.html', error=error)


# 查询参数
@app.route('/demo', methods=['GET'])
def search():
    key = request.args.get('user')
    return f'query 查询参数的值：{key}'



if __name__ == '__main__':
    app.run()
